﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Chapter24.Examples
{
    using System.Xml.Linq;
    using Databases;

    public class Code10
    {
        public static void BeginEx06()
        {
            var entities = new AdventureWorks2008Entities();
            var customerOrders =
                new XElement("addresses",
                    from a in entities.Addresses.Take(5).AsEnumerable()
                    select new XElement("address",
                        new XAttribute("ID", a.AddressID),
                        new XAttribute("Line1", a.AddressLine1),
                          from b in a.BusinessEntityAddresses
                          select new XElement("bussiness",
                              new XAttribute("Year", b.BusinessEntity.ModifiedDate.Year),
                              new XAttribute("BusinessEntityID", b.BusinessEntityID),
                              new XAttribute("Day", b.BusinessEntity.ModifiedDate.Day),
                              new XAttribute("Month", b.BusinessEntity.ModifiedDate.Month)
                          )
                      )
                  );
            var xmlFileName = @".\customer-orders.xml";
            Console.WriteLine("Successfully saved AdventureWorks2008 customer orders to :");
            Console.WriteLine(xmlFileName);
            Console.WriteLine("Press Enter/Return to continue...");
            Console.ReadLine();
        }
    }
}
